package com.leokok.jts.learning.jts.core.algorithm;

import org.junit.Test;
import org.locationtech.jts.algorithm.RobustLineIntersector;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.LineSegment;
import org.locationtech.jts.geom.PrecisionModel;

/**
 * 线相交测试
 */
public class LineIntersectorTest {

    @Test
    public void computeIntersection(){
        LineSegment lineSegment1 = new LineSegment();
        lineSegment1.setCoordinates(new Coordinate(2089426.5233462777, 1180182.3877339689),new Coordinate(2085646.6891757075, 1195618.7333999649));

        LineSegment lineSegment2 = new LineSegment();
        lineSegment2.setCoordinates(new Coordinate(1889281.8148903656, 1997547.0560044837), new Coordinate(2259977.3672235999, 483675.17050843034));

        PrecisionModel precisionModel = new PrecisionModel(100);

        RobustLineIntersector robustLineIntersector = new RobustLineIntersector();
       // robustLineIntersector.setPrecisionModel(precisionModel);

//        robustLineIntersector.computeIntersection(lineSegment1.getCoordinate(0),lineSegment1.getCoordinate(1),lineSegment2.getCoordinate(0),lineSegment2.getCoordinate(1));
        robustLineIntersector.computeIntersection(lineSegment1.getCoordinate(0),lineSegment1.getCoordinate(1),lineSegment2.getCoordinate(0),lineSegment2.getCoordinate(1));

        int num = robustLineIntersector.getIntersectionNum();
        System.out.println(num);
    }
}
